<admintpl file="header" />
<style type="text/css">
.pic-list li {
	margin-bottom: 5px;
}
.w60{
	width:100px !important;
	display:block;
	float:left;	
	text-align:right;
	line-height:32px;
}
.controls_box_box{
	display:block;
	float:left;
}
</style>
<script type="text/html" id="photos-item-wrapper">
	<li id="savedimage{id}">
		<input id="photo-{id}" type="hidden" name="photos_url[]" value="{filepath}"> 
		<input id="photo-{id}-name" type="text" name="photos_alt[]" value="{name}" style="width: 160px;" title="图片名称">
		<img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;" onclick="parent.image_preview_dialog(this.src);">
		<a href="javascript:upload_one_image('图片上传','#photo-{id}');">替换</a>
		<a href="javascript:(function(){$('#savedimage{id}').remove();})();">移除</a>
	</li>
</script>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Paper/index',array('paper_type'=>$paper_type))}">试卷管理</a></li>
			<li class="active"><a href="{:U('Paper/add',array('paper_type'=>$paper_type))}" target="_self">编辑试卷</a></li>
			
		</ul>
		<form action="{:U('Paper/edit_paper')}" method="post" class="form-horizontal js-ajax-forms">
			<div class="row-fluid">
					<table class="table table-bordered">
						<tr>
							<th width="80">试卷名称</th>
							<td>
							<input type="hidden" name="id" value="{$paper['id']}"/>
							<input type="hidden" name="paper_type" value="{$paper_type}"/>
								<input type="text" style="width:200px;" name="paper_name" id="paper_name" required value="{$paper.paper_name}" placeholder="请输入试卷名称"/>
							</td>
						</tr>
						<tr>
							<th width="80">所属分类</th>
							<td>
								<select style="max-height: 100px;" name="paper_term" id="paper_term">{$taxonomys}</select>
							</td>
						</tr>						
						<tr>
							<th width="80">评卷方式</th>
							<td>
								<select style="max-height: 100px;" name="paper_judge_type" id="paper_judge_type">
								<option value="0">电脑评卷</option>
								<option value="1">教师评卷</option>
								</select>
								教师评卷时有主观题则需要教师在后台评分后才能显示分数，无主观题自动显示分数。
							</td>
						</tr>
						<tr>
							<th width="80">试卷状态</th>
							<td>
								<select style="max-height: 100px;" name="paper_status" id="paper_status">
								<option value="0">启用</option>
								<option value="1">停用</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>试卷总分</th>
							<td>
								<input type="text" style="width:200px;" name="paper_score" id="paper_score" required value="{$paper.paper_score}" placeholder="请输入分数"/>分
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>通过总分</th>
							<td>
								<input type="text" style="width:200px;" name="paper_pass_score" id="paper_pass_score" required value="{$paper.paper_pass_score}" placeholder="请输入分数"/>分
								<span class="form-required">*</span>
							</td>
						</tr>
						
						<tr>
							<th>题型排序</th>
							<td><div class="sortable btn-group">
								<volist name="question_types" id="vo">
									<a class="btn btn-primary ui-state-default">{$question_types[$key]}<input type="hidden" name="paper_setting[questypelite][{$key}]" class="questypepanelinput" id="panel_{$key}" value="{$key}"/></a>
								</volist>
							</div>
							手动拖动题型按钮对题型进行排序
 						</td>
						</tr>
						<tr>
							<th>选题方式</th>
							<td>
							  <div class="radio inline">
							  <label>
							      <input type="radio" name="paper_choose_type" value="0" checked> 随机选题
							  </label>
							  </div>
							  <div class="radio inline">
							    <label>
							      <input type="radio" name="paper_choose_type" value="1"> 手动选题
							    </label>
							  </div>
 							</td>
						</tr>
						<tr>
							<th>题目设置</th>
							<td>
							 <div id="rand_panel" style="margin-top:20px">
							 	<volist name="question_types" id="vo">
								<div class="control-group">
									<label class="w60" for="content">{$vo}：</label>
									<div class="controls_box">
										<span class="info">共&nbsp;</span> <input
											id="iselectallnumber_{$key}" type="text" class="input-mini iselectallnumber"
											needle="needle" name="paper_setting[questype][{$key}][number]"
											value="{$paper_setting['questype'][$key]['number']}" size="2" msg="您必须填写总题数" /> <span class="info">&nbsp;题，每题&nbsp;</span><input
											class="input-mini" needle="needle" type="text"
											name="paper_setting[questype][{$key}][score]" value="{$paper_setting['questype'][$key]['score']}"
											size="2" msg="您必须填写每题的分值" /> <span class="info">&nbsp;分，描述&nbsp;</span><input
											class="input-mini" type="text"
											name="paper_setting[questype][{$key}][describe]" value="{$paper_setting['questype'][$key]['describe']}"
											size="12" /> 
											<span class="info modal-box">
											<button onclick="show_ques_layer({$key})" type="button" class="btn btn-primary">选题</button>
											</span>
											<span class="level-box">
											
											<span class="info">&nbsp;难度题数：</span>
											<foreach name="question_level" item="qname" key="no">								
											<span class="info">&nbsp;{$qname}&nbsp;</span><input class="input-mini" type="text" name="paper_setting[questype][{$key}][level{$no}]" value="{$paper_setting['questype'][$key]["level$no"]}" size="2" msg="您需要填写{$qname}题的数量，最小为0" />
											</foreach>
											<input type="hidden" id="ques_list{$key}" name="paper_setting[questype][{$key}][ques_list]" value="{$paper_setting['questype'][$key]['ques_list']}" />
											</span>
									</div>
								</div>
								</volist>								
							</div>
						</td>
						</tr>
						<tr>
							<th>试卷排序</th>
							<td><input type="text" name="listorder" id="listorder" value="{$paper.listorder}" style="width: 200px" placeholder="选填">值越小越先前 </td>
						</tr>
						<tr>
							<th>试卷来源</th>
							<td><input type="text" name="paper_source" id="paper_source" value="{$paper.paper_source}" style="width: 400px" placeholder="请输入试卷来源"></td>
						</tr>
					</table>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Paper/index')}">返回</a>
			</div>
		</form>
	</div>
	
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script src="__PUBLIC__/js/cookie.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>
	<script type="text/javascript">
function setqueslist(paper_type,list)
{
	var current_ques_ids_arr=new Array();
	//关闭层
	layer.closeAll();
	if(list!=null&&list.length>0){
		//设置待提交数据
		$("#ques_list"+paper_type).val(list);
		$.cookie('current_ques_ids'+paper_type,null);
		current_ques_ids_arr=list.split(',');
		//填充表单
		$("#iselectallnumber_"+paper_type).val(current_ques_ids_arr.length);
	}
	else{
		$("#ques_list"+paper_type).val(list);
		$("#iselectallnumber_"+paper_type).val(0);
	}
}
function show_ques_layer(paper_type){
	if($("#ques_list"+paper_type).val().length>0){
		$.cookie('current_ques_ids'+paper_type,$("#ques_list"+paper_type).val());
	}
	layer.open({
	      type: 2,
	      title: '试卷选题',
	      shadeClose: true,
	      shade: false,
	      maxmin: true, //开启最大化最小化按钮
	      area: ['893px', '600px'],
	      content: '{:U('questions/queslist')}'+'&paper_type='+paper_type,
	      success:function(layero, index){
	    	  layer.full(index);
	      }
	});
}
$(function() {
	$('#paper_term').val({$paper['paper_term']});
	$('#paper_judge_type').val({$paper['paper_judge_type']});
	$('#paper_status').val({$paper['paper_status']});
	$('.radio input:radio[value={$paper['paper_choose_type']}]').attr('checked',true);
	$('.radio input:radio').change(function(){
		if($(this).attr('checked')&&$(this).val()==1){
			$('.modal-box').show();
			$('.level-box').hide();
			$('.iselectallnumber').attr('readonly',true);
		}
		else{
			$('.modal-box').hide();
			$('.level-box').show();
			$('.iselectallnumber').attr('readonly',false);
		}
	});
	$('.radio input:radio').change();

	$(".sortable").sortable({
      placeholder: "ui-state-highlight"
    });
	$(".sortable").disableSelection();
	$(".js-ajax-close-btn").on('click', function(e) {
		e.preventDefault();
		Wind.use("artDialog", function() {
			art.dialog({
				id : "question",
				icon : "question",
				fixed : true,
				lock : true,
				background : "#CCCCCC",
				opacity : 0,
				content : "您确定需要关闭当前页面嘛？",
				ok : function() {
					setCookie("refersh_time", 1);
					window.close();
					return true;
				}
			});
		});
	});
	/////---------------------
	Wind.use('validate', 'ajaxForm', 'artDialog', function() {
		//javascript
		var form = $('form.js-ajax-forms');
		//ie处理placeholder提交问题
		if ($.browser && $.browser.msie) {
			form.find('[placeholder]').each(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			});
		}
		var formloading = false;
		//表单验证开始
		form.validate({
			//是否在获取焦点时验证
			onfocusout : false,
			//是否在敲击键盘时验证
			onkeyup : false,
			//当鼠标掉级时验证
			onclick : false,
			//验证错误
			showErrors : function(errorMap, errorArr) {
				console.log(errorMap);
				//errorMap {'name':'错误信息'}
				//errorArr [{'message':'错误信息',element:({})}]
				try {
					$(errorArr[0].element).focus();
					art.dialog({
						id : 'error',
						icon : 'error',
						lock : true,
						fixed : true,
						background : "#CCCCCC",
						opacity : 0,
						content : errorArr[0].message,
						cancelVal : '确定',
						cancel : function() {
							$(errorArr[0].element).focus();
						}
					});
				} catch (err) {
				}
			},
			//验证规则
			rules : {
				paper_name : {
					required : true
				},
				paper_score : {
					required : true
				},
				paper_pass_score : {
					required : true
				}
			},
			//验证未通过提示消息
			messages : {
				paper_name : {
					required : '请填写试卷名称'
				},
				paper_score : {
					required : '请填写试卷分数'
				},
				paper_pass_score : {
					required : '请填写通过分数'
				}
			},
			//给未通过验证的元素加效果,闪烁等
			highlight : false,
			//是否在获取焦点时验证
			onfocusout : false,
			//验证通过，提交表单
			submitHandler : function(forms) {
				if (formloading)
					return;
				$(forms).ajaxSubmit({
					url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
					dataType : 'json',
					beforeSubmit : function(arr, $form, options) {
						formloading = true;
					},
					success : function(data, statusText, xhr, $form) {
						formloading = false;
						if (data.status) {
							setCookie("refersh_time", 1);
							//编辑成功
							Wind.use("artDialog", function() {
								art.dialog({
									id : "succeed",
									icon : "succeed",
									fixed : true,
									lock : true,
									background : "#CCCCCC",
									opacity : 0,
									content : data.info,
									button : [ {
										name : '继续编辑？',
										callback : function() {
											reloadPage(window);
											return true;
										},
										focus : true
									}, {
										name : '返回列表页',
										callback : function() {
											location = "{:U('Paper/index',array('paper_type'=>$paper_type))}";
											return true;
										}
									} ]
								});
							});
						} else {
							artdialog_alert(data.info);
						}
					}
				});
			}
		});
	});
	////-------------------------
});
	</script>
</body>
</html>